import request, { type ListQuery, type ListResponse } from "@/utils/request";
import { type UserProfileType } from "./profile";

const RECHARGE_BASE_URL = "/api";

export const RechargeAPI = {
  getRechargeList: (params: RechargeListQuery) => {
    return request.get<any, ListResponse<RechargeItemType>>(
      `${RECHARGE_BASE_URL}/internal/RechargeOrder/`,
      { params }
    );
  },
  getRechargeDetail: (id: number) => {
    return request.get(`${RECHARGE_BASE_URL}/internal/RechargeOrder/${id}/`);
  },
  createRecharge: (data: Partial<RechargeForm>) => {
    return request.post(`${RECHARGE_BASE_URL}/internal/RechargeOrder/`, data);
  },
  updateRecharge: (data: Partial<RechargeForm>) => {
    return request.put(`${RECHARGE_BASE_URL}/internal/RechargeOrder/${data.id}/`, data);
  },
  deleteRecharge: (id: number) => {
    return request.delete(`${RECHARGE_BASE_URL}/internal/RechargeOrder/${id}/`);
  },
};

export type RechargeListQuery = {} & ListQuery;

/**
 * @description 充值订单状态
 * @property {string} pending - 待支付
 * @property {string} completed - 已完成
 * @property {string} canceled - 已取消
 */
export type RechargeStatusType = "pending" | "completed" | "canceled";

export type RechargeItemType = {
  id: number;
  user: UserProfileType;
  created_at: string;
  updated_at: string;
  is_active: boolean;
  amount: string;
  status: RechargeStatusType;
  payment_id: number;
};

export type RechargeForm = {
  id?: number;
  user: number;
  amount: string;
  payment_id: number;
};

export default RechargeAPI;
